package nju.mscs.gui;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;

import java.awt.IllegalComponentStateException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import nju.mscs.businesslogic.DS;
import nju.mscs.businesslogic.DataSynchronism;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Entrance_s extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}


	/*{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}*/

	private JButton jButton1;	
	private JButton jButton2;
	private JLabel jLabel2;
	private JButton jButton3;
	private JComboBox jComboBox1;
	private JLabel jLabel1;

	private DataSynchronism ds = new DS();
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Entrance_s inst = new Entrance_s();
				inst.setLocationRelativeTo(null);			
				inst.setVisible(true);		
			}
		});
	}
	
	public Entrance_s() {
		super();
		initGUI();
		
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setUndecorated(true);
			
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("\u9000\u51fa");
				jButton1.setBounds(946, 505, 200, 92);
				jButton1.setFont(new java.awt.Font("微软雅黑",0,36));
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jButton1ActionPerformed(evt);
					}
				});
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("\u6b22\u8fce\u4f7f\u7528\u8d85\u5e02\u7ba1\u7406\u7cfb\u7edf\u5206\u5e97\u5ba2\u6237\u7aef");
				jLabel1.setBounds(341, 69, 781, 97);
				jLabel1.setFont(new java.awt.Font("微软雅黑",0,48));
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("\u767b\u5f55");
				jButton2.setBounds(171, 505, 218, 92);
				jButton2.setFont(new java.awt.Font("微软雅黑",0,36));
				jButton2.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jButton2ActionPerformed(evt);
					}
				});
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("\u8bf7\u9009\u62e9\u60a8\u7684\u8eab\u4efd\u8fdb\u884c\u767b\u5f55");
				jLabel2.setBounds(487, 199, 437, 60);
				jLabel2.setFont(new java.awt.Font("微软雅黑",0,36));
			}
			{
				ComboBoxModel jComboBox1Model = 
					new DefaultComboBoxModel(
							new String[] { "收银员", "分店经理","系统管理员" });
				jComboBox1 = new JComboBox();
				getContentPane().add(jComboBox1);
				jComboBox1.setModel(jComboBox1Model);
				jComboBox1.setBounds(564, 326, 277, 70);
				jComboBox1.setFont(new java.awt.Font("微软雅黑",0,28));
			}
			{
				jButton3 = new JButton();
				getContentPane().add(jButton3);
				jButton3.setText("\u540c\u6b65");
				jButton3.setBounds(600, 505, 195, 92);
				jButton3.setFont(new java.awt.Font("微软雅黑",0,36));
				jButton3.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jButton3ActionPerformed(evt);
					}
				});
			}

			pack();
			this.setSize(1278, 689);
			getGraphicsConfiguration().getDevice().setFullScreenWindow(this);
			
			
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	private void jButton1ActionPerformed(ActionEvent evt) {
		//System.out.println("jButton1.actionPerformed, event="+evt);
		int i=0;
		Boolean result1=false;
		while(i<3){
			result1  = ds.update();
			i++;
			if(result1)
				System.exit(1);
		}
		JOptionPane.showMessageDialog(this,"数据更新失败！ ");
		System.exit(1);
	}
	
	private void jButton2ActionPerformed(ActionEvent evt) {
		//System.out.println("jButton2.actionPerformed, event="+evt);
		String job = jComboBox1.getSelectedItem().toString();
		if(job.equals("收银员")){
			login1.main(null);
		    this.dispose();
		}
		if(job.equals("分店经理")){
			login2.main(null);
			this.dispose();
		}
		if(job.equals("系统管理员")){
			CopyOflogin4_m.main(null);
			CopyOflogin4_m.setKey("2");
			this.dispose();
		}
	
	}
	
	private void jButton3ActionPerformed(ActionEvent evt) {
		//System.out.println("jButton3.actionPerformed, event="+evt);
		int i=0;
		boolean bool=true;
		while(i<3){
			Boolean result = ds.downLoad();
			i++;
			if(result){
				JOptionPane.showMessageDialog(this,"数据更新成功！ ");
				bool=false;
				return;
			}
		}
		if(bool){
			JOptionPane.showMessageDialog(this,"数据更新失败！ ");
			return;
		}
	}//同步按钮

}
